<?php

function formatStringContent($content) {
    $content = strip_tags($content, '<br> <hr> <p> <strong> <b> <i> <u>');
    $content = str_replace('　', ' ', $content);
    $content = str_replace('&nbsp;', ' ', $content);
    $content = str_replace("　", " ", $content);
    $content = preg_replace("/&([^;&]*)(;|&)/", "", $content);
    $content = preg_replace("/[ ]+/s", " ", $content);
    $content = trim($content);
    return $content;
}

function SpHtml2Text($str) {
    $str = preg_replace("/<sty(.*)\\/style>|<scr(.*)\\/script>|<!--(.*)-->/isU", "", $str);
    $alltext = "";
    $start = 1;
    for ($i = 0; $i < strlen($str); $i++) {
        if ($start == 0 && $str[$i] == ">") {
            $start = 1;
        } else if ($start == 1) {
            if ($str[$i] == "<") {
                $start = 0;
                $alltext .= " ";
            } else if (ord($str[$i]) > 31) {
                $alltext .= $str[$i];
            }
        }
    }
    $alltext = str_replace("　", " ", $alltext);
    $alltext = preg_replace("/&([^;&]*)(;|&)/", "", $alltext);
    $alltext = preg_replace("/[ ]+/s", " ", $alltext);
    return $alltext;
}

if (!function_exists('Html2Text')) {

    function Html2Text($str, $r = 0) {
        if ($r == 0) {
            return SpHtml2Text($str);
        } else {
            $str = SpHtml2Text(stripslashes($str));
            return addslashes($str);
        }
    }

}
?>
